package generator.addons;

import java.util.HashMap;
import java.util.Random;

/**
 *
 * @author Necro
 */
public class DataSet<T> {
    HashMap<Integer,T> data;

    public DataSet() {
        this.data = new HashMap<Integer,T>();
    }

    public T get(Object key) {
        return data.get(key);
    }

    public int size() {
        return data.size();
    }

    public boolean isEmpty() {
        return data.isEmpty();
    }

    public void add(Integer key,T e) {
        data.put(key, e);
    }
    
    public T getRand(){
        Random rand = new Random();
        T res = (T) data.values().toArray()[rand.nextInt(data.size())];
        return res;
    }
    
    public T poolRand(){
        Random rand = new Random();
        T res = (T) data.values().toArray()[rand.nextInt(data.size())];
        data.remove(res);
        return res;
    }
    
    public T rand(int i){
        Random rand=new Random();
        int tmp = rand.nextInt(100);
        if (tmp < i){
            return this.poolRand();
        } else {
            return this.getRand();
        }
    }
    
    public void printAll(){
        for(Integer tmp: data.keySet()){
            //@todo do przerobienia na output stream
            System.out.println(data.get(tmp).toString());
        }
    }
}
